package com.lframework.xingyun.basedata.mappers;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.lframework.starter.web.core.mapper.BaseMapper;
import com.lframework.xingyun.basedata.bo.coupon.QueryCouponStopBo;
import com.lframework.xingyun.basedata.entity.CouponStop;
import com.lframework.xingyun.basedata.entity.Shop;
import com.lframework.xingyun.basedata.vo.coupon.QueryCouponStopVo;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * <p>
 * 卡券和门店关系表 Mapper 接口
 * </p>
 *
 */
@Mapper
public interface CouponStopMapper extends BaseMapper<CouponStop> {

    /**
     * 查询分页
     * @param vo
     * @return
     */
    default IPage<QueryCouponStopBo> queryPage(QueryCouponStopVo vo) {
        return defaultJoinWrapper()
                .selectAll(CouponStop.class)
                .selectAs(Shop::getName, QueryCouponStopBo::getStopName)
                .leftJoin(Shop.class, Shop::getId, CouponStop::getStopId)
                .eq(StrUtil.isNotBlank(vo.getCouponId()), CouponStop::getCouponId, vo.getCouponId())
                .page(PageDTO.of(vo.getPageIndex(), vo.getPageSize()), QueryCouponStopBo.class);
    }

    /**
     * 查询列表
     * @param vo
     * @return
     */
    default List<QueryCouponStopBo> queryList(QueryCouponStopVo vo) {
        return defaultJoinWrapper()
                .selectAll(CouponStop.class)
                .selectAs(Shop::getName, QueryCouponStopBo::getStopName)
                .leftJoin(Shop.class, Shop::getId, CouponStop::getStopId)
                .eq(StrUtil.isNotBlank(vo.getCouponId()), CouponStop::getCouponId, vo.getCouponId())
                .list(QueryCouponStopBo.class);
    }
}

